package org.ziletech.service;

import java.io.Serializable;
import java.sql.Connection;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.executor.BatchResult;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
public interface BaseService<T,PK extends Serializable> {
	 /**
	   * @author tonyli
	   * @param <T> the returned object type
	   * @param statement
	   * @return Mapped object
	   */
	  public <T> T selectOne(String statement);

	 /**
	   * @author tonyli
	   * @param <T> the returned object type
	   * @param statement Unique identifier matching the statement to use.
	   * @param parameter A parameter object to pass to the statement.
	   * @return Mapped object
	   */
	  public <T> T selectOne(String statement, Object parameter);

	 /**
	   * @author tonyli
	   * Retrieve a list of mapped objects from the statement key and parameter.
	   * @param <E> the returned list element type
	   * @param statement Unique identifier matching the statement to use.
	   * @return List of mapped object
	   */
	  public <E> List<E> selectList(String statement);


		 /**
		   * @author tonyli
		   * Retrieve a list of mapped objects from the statement key and parameter.
		   * @param <E> the returned list element type
		   * @param statement Unique identifier matching the statement to use.
		   * @param parameter A parameter object to pass to the statement.
		   * @return List of mapped object
		   */
	  public <E> List<E> selectList(String statement, Object parameter);
	  
	  
	  
	  /**
	   * @author tonyli
	   * Retrieve a list of mapped objects from the statement key and parameter,
	   * within the specified row bounds.
	   * @param <E> the returned list element type
	   * @param statement Unique identifier matching the statement to use.
	   * @param parameter A parameter object to pass to the statement.
	   * @param rowBounds  Bounds to limit object retrieval
	   * @return List of mapped object
	   */
	  <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds);

	  /**
	   * @author tonyli
	   * The selectMap is a special case in that it is designed to convert a list
	   * of results into a Map based on one of the properties in the resulting
	   * objects.
	   * Eg. Return a of Map[Integer,Author] for selectMap("selectAuthors","id")
	   * @param <K> the returned Map keys type
	   * @param <V> the returned Map values type
	   * @param statement Unique identifier matching the statement to use.
	   * @param mapKey The property to use as key for each value in the list.
	   * @return Map containing key pair data.
	   */
	  <K, V> Map<K, V> selectMap(String statement, String mapKey);

	  /**
	   * @author tonyli
	   * The selectMap is a special case in that it is designed to convert a list
	   * of results into a Map based on one of the properties in the resulting
	   * objects.
	   * @param <K> the returned Map keys type
	   * @param <V> the returned Map values type
	   * @param statement Unique identifier matching the statement to use.
	   * @param parameter A parameter object to pass to the statement.
	   * @param mapKey The property to use as key for each value in the list.
	   * @return Map containing key pair data.
	   */
	  <K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey);

	  /**
	   * @author tonyli
	   * The selectMap is a special case in that it is designed to convert a list
	   * of results into a Map based on one of the properties in the resulting
	   * objects.
	   * @param <K> the returned Map keys type
	   * @param <V> the returned Map values type
	   * @param statement Unique identifier matching the statement to use.
	   * @param parameter A parameter object to pass to the statement.
	   * @param mapKey The property to use as key for each value in the list.
	   * @param rowBounds  Bounds to limit object retrieval
	   * @return Map containing key pair data.
	   */
	  <K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds);

	  /**
	   * @author tonyli
	   * Retrieve a single row mapped from the statement key and parameter
	   * using a {@code ResultHandler}.
	   * @param statement Unique identifier matching the statement to use.
	   * @param parameter A parameter object to pass to the statement.
	   * @param handler ResultHandler that will handle each retrieved row
	   * @return Mapped object
	   */
	  void select(String statement, Object parameter, ResultHandler handler);

	  /**
	   * @author tonyli
	   * Retrieve a single row mapped from the statement
	   * using a {@code ResultHandler}.
	   * @param statement Unique identifier matching the statement to use.
	   * @param handler ResultHandler that will handle each retrieved row
	   * @return Mapped object
	   */
	  void select(String statement, ResultHandler handler);

	  /**
	   * @author tonyli
	   * Retrieve a single row mapped from the statement key and parameter
	   * using a {@code ResultHandler} and {@code RowBounds}
	   * @param statement Unique identifier matching the statement to use.
	   * @param rowBounds RowBound instance to limit the query results
	   * @param handler ResultHandler that will handle each retrieved row
	   * @return Mapped object
	   */
	  void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler);

	  /**
	   * @author tonyli
	   * Execute an insert statement.
	   * @param statement Unique identifier matching the statement to execute.
	   * @return int The number of rows affected by the insert.
	   */
	  int insert(String statement);

	  /**
	   * @author tonyli
	   * Execute an insert statement with the given parameter object. Any generated
	   * autoincrement values or selectKey entries will modify the given parameter
	   * object properties. Only the number of rows affected will be returned.
	   * @param statement Unique identifier matching the statement to execute.
	   * @param parameter A parameter object to pass to the statement.
	   * @return int The number of rows affected by the insert.
	   */
	  int insert(String statement, Object parameter);

	  /**
	   * @author tonyli
	   * Execute an update statement. The number of rows affected will be returned.
	   * @param statement Unique identifier matching the statement to execute.
	   * @return int The number of rows affected by the update.
	   */
	  int update(String statement);

	  /**
	   * @author tonyli
	   * Execute an update statement. The number of rows affected will be returned.
	   * @param statement Unique identifier matching the statement to execute.
	   * @param parameter A parameter object to pass to the statement.
	   * @return int The number of rows affected by the update.
	   */
	  int update(String statement, Object parameter);

	  /**
	   * @author tonyli
	   * Execute a delete statement. The number of rows affected will be returned.
	   * @param statement Unique identifier matching the statement to execute.
	   * @return int The number of rows affected by the delete.
	   */
	  int delete(String statement);

	  /**
	   * @author tonyli
	   * Execute a delete statement. The number of rows affected will be returned.
	   * @param statement Unique identifier matching the statement to execute.
	   * @param parameter A parameter object to pass to the statement.
	   * @return int The number of rows affected by the delete.
	   */
	  int delete(String statement, Object parameter);

	  /**
	   * @author tonyli
	   * Flushes batch statements and commits database connection.
	   * Note that database connection will not be committed if no updates/deletes/inserts were called.
	   * To force the commit call {@link SqlSession#commit(boolean)}
	   */
	  void commit();

	  /**
	   * @author tonyli
	   * Flushes batch statements and commits database connection.
	   * @param force forces connection commit
	   */
	  void commit(boolean force);

	  /**
	   * @author tonyli
	   * Discards pending batch statements and rolls database connection back.
	   * Note that database connection will not be rolled back if no updates/deletes/inserts were called.
	   * To force the rollback call {@link SqlSession#rollback(boolean)}
	   */
	  void rollback();

	  /**
	   * @author tonyli
	   * Discards pending batch statements and rolls database connection back.
	   * Note that database connection will not be rolled back if no updates/deletes/inserts were called.
	   * @param force forces connection rollback
	   */
	  void rollback(boolean force);

	  /**
	   * @author tonyli
	   * Flushes batch statements.
	   * @return BatchResult list of updated records
	   * @since 3.0.6
	   */
	  List<BatchResult> flushStatements();

	  /**
	   * @author tonyli
	   * Closes the session
	   */
	  void close();

	  /**
	   * @author tonyli
	   * Clears local session cache
	   */
	  void clearCache();

	  /**
	   * @author tonyli
	   * Retrieves current configuration
	   * @return Configuration
	   */
	  Configuration getConfiguration();

	  /**
	   * @author tonyli
	   * Retrieves a mapper.
	   * @param <T> the mapper type
	   * @param type Mapper interface class
	   * @return a mapper bound to this SqlSession
	   */
	  <T> T getMapper(Class<T> type);

	  /**
	   * @author tonyli
	   * Retrieves inner database connection
	   * @return Connection
	   */
	  Connection getConnection();
}
